import axios from 'axios';

// 封装请求
export function request(method,url,data){
    return new Promise((resolve,reject) => {
        if(method=="get"){
            axios({
                method:method,
                url:url,
                params:data
            }).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        }
        else{
            axios({
                method:method,
                url:url,
                data:data
            }).then(res => {
                resolve(res.data);
            }).catch(err => {
                reject(err.data)
            })
        }
    })
}

// 请求拦截器
axios.interceptors.request.use( request =>{
    // let token = JSON.parse(sessionStorage.getItem("token"));
    let token = sessionStorage.getItem("token");
    request.headers.Authorization = token
    request.headers['Content-Type'] = 'application/json; charset=utf-8';
    return request

}
);